﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    ///  ItemCls业务逻辑层
    /// </summary>
    public partial class ItemCls
    {
        /// <summary>
        /// 组织机构的DAL
        /// </summary>
        private readonly DAL.ItemCls dal = new DAL.ItemCls();
        /// <summary>
        /// 查询数据列表
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-9-22</date>
        /// <param name="strWhere">where条件</param>
        /// <returns>List集合</returns>
        public List<Model.ItemCls> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 查询数据列表
        /// </summary>
        /// <creator>zhongyl</creator>
        /// <date>2013-9-29</date>
        /// <param name="strWhere">where条件</param>
        /// <returns>List集合</returns>
        public List<Model.ItemCls> GetModelListAll(string strWhere)
        {
            DataSet ds = dal.GetListAll(strWhere);
            return DataTableToList(ds.Tables[0]);
        }


        /// <summary>
        /// 通过编号得到对象
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>DataTableToList表</returns>
        public List<Model.ItemCls> GetListByClsNo(string entityNo)
        {
            DataSet ds = dal.GetListByClsNo(entityNo);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-9-22</date>
        /// <param name="dt">表数据</param>
        /// <returns>List集合</returns>
        public List<Model.ItemCls> DataTableToList(DataTable dt)
        {
            List<Model.ItemCls> modelList = new List<Model.ItemCls>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0) {
                Model.ItemCls model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.ItemCls();
                    if (dt.Rows[n]["FItemClsNo"] != null)
                    {
                        model.FItemClsNo = dt.Rows[n]["FItemClsNo"].ToString();
                    }
                    if (dt.Rows[n]["FItemClsName"] != null && dt.Rows[n]["FItemClsName"].ToString() != "")
                    {
                        model.FItemClsName = dt.Rows[n]["FItemClsName"].ToString();
                    }
                    if (dt.Rows[n]["FEntityNo"] != null && dt.Rows[n]["FEntityNo"].ToString() != "")
                    {
                        model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 得到一个实体对象
        /// </summary>
        /// <param name="itemClsNo">用品编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>实体对象</returns>
        public ElingOA6_Admin_DSJCJ.Model.ItemCls GetModel(string itemClsNo, string entityNo)
        {
            return dal.GetModel(itemClsNo, entityNo);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <param name="itemClsNo">用品编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>是否存在</returns>
        public bool Exists(string itemClsNo, string entityNo)
        {
            return dal.Exists(itemClsNo, entityNo);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="itemClsNo">用品编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>是否删除</returns>
        public bool Delete(string itemClsNo, string entityNo)
        {

            return dal.Delete(itemClsNo, entityNo);
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model对象</param>
        /// <returns>是否添加</returns>
        public bool Add(ElingOA6_Admin_DSJCJ.Model.ItemCls model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">model对象</param>
        /// <returns>是否更新</returns>
        public bool Update(ElingOA6_Admin_DSJCJ.Model.ItemCls model)
        {
            return dal.Update(model);
        }
        
    }
}
